﻿using Dao.Corpus;
using ShareCode.Entity.Corpus;
using Infrastructure.Attributes.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShareCode.Dto;
using Infrastructure.Util.Helper;
using ShareCode.KeyValue;

namespace Bll.Corpus
{
    /// <summary>
    /// by zhouxin
    ///</summary>
    [Component]
    public class CorpusVersionBll : BaseTreeBll<CorpusVersionEntity>
    {
        protected override CorpusVersionDao? Dao => (CorpusVersionDao?)base.Dao;

        [Autowired]
        public CorpusVersionDao SetDao { set { this._Dao = value; } }


        public async Task<bool> TreeInsertSonWithCover(FileUploadDto<CorpusVersionEntity> entity)
        {
            if (entity.Model == null)
            {
                return false;
            }

            if (entity.Files != null)
            {
                var filePath = UploadFileHelper.SaveFormFile(entity.Files!, EnumFileUsage.CorpusVersionCover);
                if (filePath != null)
                {
                    entity.Model.Cover = filePath;
                }
            }

            return await Dao!.TreeInsertSon(entity.Model);

        }
        public async Task<bool> UpdataWithCover(FileUploadDto<CorpusVersionEntity> entity)
        {
            if (entity.Model == null)
            {
                return false;
            }

            if (entity.Files != null)
            {
                var filePath = UploadFileHelper.SaveFormFile(entity.Files!, EnumFileUsage.CorpusVersionCover);
                if (filePath != null)
                {
                    entity.Model.Cover = filePath;
                }
            }

            return await this.UpdateAsync(entity.Model);

        }


    }
}
